#ifndef CONFIGMANAGE_H
#define CONFIGMANAGE_H

#include <QObject>
#include <QFile>
#include <QDateTime>
#include <QCryptographicHash>
#include <QJsonObject>

class ConfigManage : public QObject
{
    Q_OBJECT
public:
    enum class UpdateFlag{
        UF_StartUpdate,
        UF_Loading,
        UF_UpdateComplete
    };
    Q_ENUM(UpdateFlag)
    explicit ConfigManage(QObject *parent = nullptr);
    
    bool init();
    bool readSddmd();
    bool readVersion();
    bool readTip();
    bool readAutoUpdate();
    bool readSNCode();
    bool readTasks();
    
    void wirteUpdateLoadingFlag(UpdateFlag flag);
    bool isExistBreakOff();
    bool writeUpdatePackageDate(const QList<QJsonObject>);
    bool writeUpdatePackageDate_null();
    bool readBreakOffDate(QList<QJsonObject>&);
    bool delUpatePackageDate();
    void writeSDDMRegister(bool);
    void writeNewVersion(QString version,QString model);
    bool readHost();
    void writeEsportBoxBindAgent(bool,bool);
    
    QString removeLeadingZeros(const QString& str);
    //get and set
    QString productKey() const;
    void setProductKey(const QString &newProductKey);
    
    QString productScrent() const;
    void setProductScrent(const QString &newProductScrent);
    
    QString productVersion() const;
    void setProductVersion(const QString &newProductVersion);
    
    QString productModule() const;
    void setProductModule(const QString &newProductModule);
    
    QString deviceId() const;
    void setDeviceId(const QString &newDeviceId);
    
    int tipTimeStatus() const;
    void setTipTimeStatus(int newTipTimeStatus);
    
    QDateTime tipTime() const;
    void setTipTime(const QDateTime &newTipTime);
    
    bool autoUpgrade() const;
    void setAutoUpgrade(bool newAutoUpgrade);
    
    QList<QJsonObject> updatePackageList() const;
    void setUpdatePackageList(const QList<QJsonObject> &newUpdatePackageList);
    
    QString secret_outBase64() const;
    void setSecret_outBase64(const QString &newSecret_outBase64);
    
    QString productSalt() const;
    void setProductSalt(const QString &newProductSalt);
    
    int deviceNode() const;
    void setDeviceNode(int newDeviceNode);
    
    QString hostname() const;
    void setHostname(const QString &newHostname);
    
    QString devicename() const;
    void setDevicename(const QString &newDevicename);
    
    int portRegister() const;
    void setPortRegister(int newPortRegister);
    
    int portDaemon() const;
    void setPortDaemon(int newPortDaemon);
    
    QString urlBindAgent() const;
    
    QString urlMacIP() const;
    
    quint64 timeout() const;
    
private:
    QString m_productKey;
    QString m_productScrent;
    QString m_productVersion;
    QString m_productModule;
    QString m_productSalt;
    
    int m_deviceNode = 0;                    // 设备节点编号
    QString m_deviceId;
    
    int m_tipTimeStatus = 0;
    QDateTime m_tipTime{};
    bool m_autoUpgrade = false;
    QList<QJsonObject> m_updatePackageList;
    
    QString m_secret_outBase64;
    
    QString m_hostname;
    QString m_devicename;
    QString m_urlBindAgent;
    QString m_urlMacIP;
    
    int m_portRegister;
    int m_portDaemon;
    quint64 m_timeout;
public slots:
    void onTipstatus(int);
    void onReadWallpaper(QString user);
    void onWriteQRCodeUrl(QJsonObject);
signals:
    void sigUserWallpaperPath(QString);
};


#endif // CONFIGMANAGE_H
/*
 * 配置文件管理类，新旧配置文件都在这里；
 * 注:类里面的一些属性方法，大多是从旧版os_daemon移植过来的，存在属性和或方法，没有调用的情况;
*/
